import { queryLevel, addLevel,removeLevel,updateLevel,querySensitiveWordsList,checkSensitiveLeveRule} from '@/services/bnsConfig/level';

export default {
  namespace: 'level',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryLevel, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addLevel, payload);
      yield put({
        type: 'saveAdd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeLevel, payload);
      yield put({
        type: 'saveRemove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateLevel, payload);
      yield put({
        type: 'saveUpdate',
        payload: response,
      });
      if (callback) callback(response);
    },
    *sensitiveWordsList({ payload, callback }, { call, put }) {
      const response = yield call(querySensitiveWordsList, payload);
      yield put({
        type: 'saveList',
        payload: response,
      });
      if (callback) callback(response);
    },
    *checkRule({ payload, callback }, { call, put }) {
      const response = yield call(checkSensitiveLeveRule, payload);
      yield put({
        type: 'saveRule',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
